﻿using System.Collections.Generic;
using System.Linq;
using Pay.Core;
using Pay.DTO;
using Pay.Service;


namespace Pay.Api.Controllers {
	public partial class OpenController : BaseController {
		#region 专题
		/// <summary>
		///  专题列表
		/// </summary>
		/// <param name="query"></param>
		/// <returns></returns>
		public ApiPagedResult<topic_dto> Topics(topic_query query) {
			var model = query.ToDtoObject<TopicQuery>();
			var oemer = _iMerchantService.Get(query.merchant_no);
			model.merchant_id = oemer.id;
			var list = _iTopicService.GetTopics(model);
			var result = new ApiPagedResult<topic_dto>(list.rows, list.total_result, list.page, list.size);
			return ApiResultToJson.Json(result);
		}

		/// <summary>
		/// 保存/编辑专题
		/// </summary>
		/// <returns>The product.</returns>
		/// <param name="model">Model.</param>
		public ApiResultMessage SaveTopic(topic_model model) {
			if (model.id > 0) {
				var dto = _iTopicService.GetTopic(model.id);
				var merchant = _iMerchantService.Get(model.merchant_no);
				var oss_set = merchant.setting.oss_set;
				var oss = new AliyunOSS(oss_set.key, oss_set.secret, oss_set.endpoint);
				var image_urls = new List<string>();
				//if (dto.show_images.Count > 0 && model.image_path.Count > 0) {
				//    //删除
				//    dto.image_path.Except(model.image_path).DataForEach(filter_id => {
				//        oss.DeleteObject(oss_set.bucket_name, filter_id.Trim('/'));
				//    });
				//}
			}
			var result = _iTopicService.Save(model);
			return ApiResultToJson.JsonData(result);
		}
		#endregion
	}
}